package com.climber.spb_shiro_custable.services;

import com.climber.spb_shiro_custable.mapper.UserDao;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl {
    @Autowired
    UserDao userDao;

    public void checkLogin(String username,String Password,boolean rememberMe){
        Subject subject= SecurityUtils.getSubject();
        UsernamePasswordToken token=new UsernamePasswordToken(username,Password,rememberMe);
        subject.login(token);
    }

    public int addUser(String username, String password,String salt,String rid) {
        Map<String ,String > para=new HashMap<>();
        para.put("username",username);
        para.put("password",password);
        para.put("salt",salt);
        para.put("roleName",rid);
        userDao.addUser(para);
        String uid=userDao.getUserByUsername(username).getUserId();
        Map<String,String> map=new HashMap<>();
        map.put("uid",uid);
        map.put("rid",rid);
        userDao.giveRole(map);
        return 0;
    }

}


